//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "CapFloor.h"
using namespace Cephei::QL::Instruments;
#include <gen/QL/Termstructures/YieldTermStructure.h>
#include <gen/QL/CashFlow.h>
#include <gen/QL/Cashflows/FloatingRateCoupon.h>
#include <gen/QL/PricingEngine.h>
#include <gen/QL/Instrument.h>
using namespace Cephei::QL::Termstructures;
using namespace Cephei::QL;
using namespace Cephei::QL::Cashflows;
#define HANDLE
#undef ABSTRACT
#define STRUCT
Cephei::QL::Instruments::CCapFloor::CCapFloor (QL::Instruments::CapFloor::TypeEnum type, Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ floatingLeg, Cephei::Core::IVector<Double>^ strikes, Cephei::QL::IPricingEngine^ QL_Pricer) : CInstrument(CCapFloor::typeid)
{
    try
    {
#ifdef HANDLE
        _phCapFloor = NULL;
#endif
        QuantLib::CapFloor::Type _type = (QuantLib::CapFloor::Type)type ;
        floatingLeg ->Lock ();
        INativeVector<Cephei::QL::ICashFlow^>^ _NCIfloatingLeg = floatingLeg->getFeature (NativeFeature::shared_ptr);
        CCashFlowVector^ _NCfloatingLeg = safe_cast<CCashFlowVector^>(_NCIfloatingLeg);
        std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _floatingLeg = static_cast<std::vector<boost::shared_ptr<QuantLib::CashFlow> >&> (_NCfloatingLeg->GetShared ());
        strikes->Lock();
        INativeVector<Double>^ _NCIstrikes = strikes->getFeature (NativeFeature::Value);
        CDoubleVector^ _NCstrikes = safe_cast<CDoubleVector^>(_NCIstrikes);
        std::vector<QuantLib::Rate>& _strikes = static_cast<std::vector<QuantLib::Rate>&> (_NCstrikes->GetReference ());
        _ppCapFloor = new boost::shared_ptr<QuantLib::CapFloor> (new QuantLib::CapFloor ( _type,  _floatingLeg,  _strikes ));
        CPricingEngine^ _CQL_Pricer = safe_cast<CPricingEngine^> (QL_Pricer);
        boost::shared_ptr<QuantLib::PricingEngine>& _QL_Pricer = static_cast<boost::shared_ptr<QuantLib::PricingEngine>&> (_CQL_Pricer->GetShared ());
        (*_ppCapFloor)->setPricingEngine (_QL_Pricer);
        SetInstrument (boost::dynamic_pointer_cast<QuantLib::Instrument> (*_ppCapFloor));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (floatingLeg != nullptr) floatingLeg->Unlock();    //not optional
        if (strikes != nullptr) strikes->Unlock();    //not optional
    }
}
Cephei::QL::Instruments::CCapFloor::CCapFloor (QL::Instruments::CapFloor::TypeEnum type, Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ floatingLeg, Cephei::Core::IVector<Double>^ capRates, Cephei::Core::IVector<Double>^ floorRates, Cephei::QL::IPricingEngine^ QL_Pricer) : CInstrument(CCapFloor::typeid)
{
    try
    {
#ifdef HANDLE
        _phCapFloor = NULL;
#endif
        QuantLib::CapFloor::Type _type = (QuantLib::CapFloor::Type)type ;
        floatingLeg ->Lock ();
        INativeVector<Cephei::QL::ICashFlow^>^ _NCIfloatingLeg = floatingLeg->getFeature (NativeFeature::shared_ptr);
        CCashFlowVector^ _NCfloatingLeg = safe_cast<CCashFlowVector^>(_NCIfloatingLeg);
        std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _floatingLeg = static_cast<std::vector<boost::shared_ptr<QuantLib::CashFlow> >&> (_NCfloatingLeg->GetShared ());
        capRates->Lock();
        INativeVector<Double>^ _NCIcapRates = capRates->getFeature (NativeFeature::Value);
        CDoubleVector^ _NCcapRates = safe_cast<CDoubleVector^>(_NCIcapRates);
        std::vector<QuantLib::Rate>& _capRates = static_cast<std::vector<QuantLib::Rate>&> (_NCcapRates->GetReference ());
        floorRates->Lock();
        INativeVector<Double>^ _NCIfloorRates = floorRates->getFeature (NativeFeature::Value);
        CDoubleVector^ _NCfloorRates = safe_cast<CDoubleVector^>(_NCIfloorRates);
        std::vector<QuantLib::Rate>& _floorRates = static_cast<std::vector<QuantLib::Rate>&> (_NCfloorRates->GetReference ());
        _ppCapFloor = new boost::shared_ptr<QuantLib::CapFloor> (new QuantLib::CapFloor ( _type,  _floatingLeg,  _capRates,  _floorRates ));
        CPricingEngine^ _CQL_Pricer = safe_cast<CPricingEngine^> (QL_Pricer);
        boost::shared_ptr<QuantLib::PricingEngine>& _QL_Pricer = static_cast<boost::shared_ptr<QuantLib::PricingEngine>&> (_CQL_Pricer->GetShared ());
        (*_ppCapFloor)->setPricingEngine (_QL_Pricer);
        SetInstrument (boost::dynamic_pointer_cast<QuantLib::Instrument> (*_ppCapFloor));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (floatingLeg != nullptr) floatingLeg->Unlock();    //not optional
        if (capRates != nullptr) capRates->Unlock();    //not optional
        if (floorRates != nullptr) floorRates->Unlock();    //not optional
    }
}
Cephei::QL::Instruments::CCapFloor::CCapFloor (boost::shared_ptr<QuantLib::CapFloor>& childNative, Object^ owner) : CInstrument(CCapFloor::typeid)
{
#ifdef HANDLE
	_phCapFloor = NULL;
#endif
	_ppCapFloor = &childNative;
    _ppInstrument = new boost::shared_ptr<QuantLib::Instrument> (boost::dynamic_pointer_cast<QuantLib::Instrument> (*_ppCapFloor));
}
Cephei::QL::Instruments::CCapFloor::CCapFloor (QuantLib::CapFloor& childNative, Object^ owner) : CInstrument(CCapFloor::typeid)
{
#ifdef HANDLE
	_phCapFloor = NULL;
#endif
	_ppCapFloor = new boost::shared_ptr<QuantLib::CapFloor> (&childNative);
    _ppInstrument = new boost::shared_ptr<QuantLib::Instrument> (boost::dynamic_pointer_cast<QuantLib::Instrument> (*_ppCapFloor));
    _CapFloorOwner = owner;
    _InstrumentOwner = owner;
}

Cephei::QL::Instruments::CCapFloor::CCapFloor (CCapFloor^ copy) : CInstrument(CCapFloor::typeid)
{
#ifdef HANDLE
	_phCapFloor = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppCapFloor = new boost::shared_ptr<QuantLib::CapFloor> (copy->GetShared());
        _ppInstrument = new boost::shared_ptr<QuantLib::Instrument> (boost::dynamic_pointer_cast<QuantLib::Instrument> (*_ppCapFloor));
    }
}
Cephei::QL::Instruments::CCapFloor::CCapFloor (PLATFORM::Type^ t) : CInstrument(CCapFloor::typeid)
{
#ifdef HANDLE
	_phCapFloor = NULL;
#endif
	if (!t->IsSubclassOf(CCapFloor::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Instruments::CCapFloor::CCapFloor (QuantLib::Handle<QuantLib::CapFloor>& childNative, Object^ owner)  : CInstrument(CCapFloor::typeid)
{
	_phCapFloor = &childNative;
	_ppCapFloor = &static_cast<boost::shared_ptr<QuantLib::CapFloor>>(childNative.currentLink());
    _ppInstrument = new boost::shared_ptr<QuantLib::Instrument> (boost::dynamic_pointer_cast<QuantLib::Instrument> (*_ppCapFloor));
    _CapFloorOwner = owner;
}
Cephei::QL::Instruments::CCapFloor::CCapFloor (QuantLib::Handle<QuantLib::CapFloor> childNative)  : CInstrument(CCapFloor::typeid)
{
	_phCapFloor = &childNative;
	_ppCapFloor = &static_cast<boost::shared_ptr<QuantLib::CapFloor>>(childNative.currentLink());
    _ppInstrument = new boost::shared_ptr<QuantLib::Instrument> (boost::dynamic_pointer_cast<QuantLib::Instrument> (*_ppCapFloor));
}
#endif
#ifdef STRUCT
Cephei::QL::Instruments::CCapFloor::CCapFloor (QuantLib::CapFloor childNative)  : CInstrument(CCapFloor::typeid)
{
#ifdef HANDLE
	_phCapFloor = NULL;
#endif
	_ppCapFloor = new boost::shared_ptr<QuantLib::CapFloor> (new QuantLib::CapFloor (childNative));
    _ppInstrument = new boost::shared_ptr<QuantLib::Instrument> (boost::dynamic_pointer_cast<QuantLib::Instrument> (*_ppCapFloor));
}
#endif

Cephei::QL::Instruments::CCapFloor::~CCapFloor ()
{
    if (_ppCapFloor != NULL)
    {
	    delete _ppCapFloor;
        _ppCapFloor = NULL;
    }
}
Cephei::QL::Instruments::CCapFloor::!CCapFloor ()
{
    if (_ppCapFloor != NULL)
    {
	    delete _ppCapFloor;
    }
}
QuantLib::CapFloor& Cephei::QL::Instruments::CCapFloor::GetReference ()
{
    if (_ppCapFloor == NULL) throw REFNEW NativeNullException ();
	return **_ppCapFloor;
}
boost::shared_ptr<QuantLib::CapFloor>& Cephei::QL::Instruments::CCapFloor::GetShared ()
{
    if (_ppCapFloor == NULL) throw REFNEW NativeNullException ();
	return *_ppCapFloor;
}
QuantLib::CapFloor* Cephei::QL::Instruments::CCapFloor::GetPointer ()
{
    if (_ppCapFloor == NULL) throw REFNEW NativeNullException ();
	return &**_ppCapFloor;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::CapFloor>& Cephei::QL::Instruments::CCapFloor::GetHandle ()
{
	if (_phCapFloor == NULL)
	{
		_phCapFloor = new Handle<QuantLib::CapFloor> (*_ppCapFloor);
	}
	return *_phCapFloor;
}
#endif
bool Cephei::QL::Instruments::CCapFloor::HasNative () 
{
	return (_ppCapFloor != NULL);
}

Double Cephei::QL::Instruments::CCapFloor::AtmRate (Cephei::QL::Termstructures::IYieldTermStructure^ discountCurve)
{
    CYieldTermStructure^ _CdiscountCurve;
    try
    {
        _CdiscountCurve = safe_cast<CYieldTermStructure^> (discountCurve);
        _CdiscountCurve->Lock();
        QuantLib::YieldTermStructure& _discountCurve = static_cast<QuantLib::YieldTermStructure&> (_CdiscountCurve->GetReference ()); 
    	QuantLib::Rate _rv = (QuantLib::Rate)(*_ppCapFloor)->atmRate ( _discountCurve );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (_CdiscountCurve != nullptr) _CdiscountCurve->Unlock();
    }
}
Cephei::Core::IVector<Double>^ Cephei::QL::Instruments::CCapFloor::CapRates::get ()
{
    try
    {
    	std::vector<QuantLib::Rate>& _rv = (std::vector<QuantLib::Rate>&)(*_ppCapFloor)->capRates ( );   
        Cephei::Core::IVector<Double>^ _nrv = REFNEW CoVector<Double> (REFNEW CDoubleVector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ Cephei::QL::Instruments::CCapFloor::FloatingLeg::get ()
{
    try
    {
    	std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _rv = (std::vector<boost::shared_ptr<QuantLib::CashFlow> >&)(*_ppCapFloor)->floatingLeg ( );   
        CoVector<Cephei::QL::ICashFlow^>^ _nrv = REFNEW CoVector<Cephei::QL::ICashFlow^>(REFNEW CCashFlowVector (_rv, this));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::Core::IVector<Double>^ Cephei::QL::Instruments::CCapFloor::FloorRates::get ()
{
    try
    {
    	std::vector<QuantLib::Rate>& _rv = (std::vector<QuantLib::Rate>&)(*_ppCapFloor)->floorRates ( );   
        Cephei::Core::IVector<Double>^ _nrv = REFNEW CoVector<Double> (REFNEW CDoubleVector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Instruments::CCapFloor::ImpliedVolatility (Double price, Cephei::QL::Termstructures::IYieldTermStructure^ disc, Double guess, Microsoft::FSharp::Core::FSharpOption<Double>^ accuracy, Microsoft::FSharp::Core::FSharpOption<UInt32>^ maxEvaluations, Microsoft::FSharp::Core::FSharpOption<Double>^ minVol, Microsoft::FSharp::Core::FSharpOption<Double>^ maxVol)
{
    CYieldTermStructure^ _Cdisc;
    try
    {
        QuantLib::Real _price = (QuantLib::Real)ValueHelper::Convert (price); //a
        _Cdisc = safe_cast<CYieldTermStructure^> (disc);
        _Cdisc->Lock();
        Handle<QuantLib::YieldTermStructure>& _disc = static_cast<Handle<QuantLib::YieldTermStructure>&> (_Cdisc->GetHandle ()); 
        QuantLib::Volatility _guess = (QuantLib::Volatility)ValueHelper::Convert (guess); //a
        QuantLib::Real _accuracy = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (accuracy) ? (QuantLib::Real)ValueHelper::Convert (accuracy->Value) : 1.0e-4); //9a
        QuantLib::Natural _maxEvaluations = 
            (Microsoft::FSharp::Core::FSharpOption<UInt32>::IsSome::get (maxEvaluations) ? (QuantLib::Natural)ValueHelper::Convert (maxEvaluations->Value) : 100); //9a
        QuantLib::Volatility _minVol = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (minVol) ? (QuantLib::Volatility)ValueHelper::Convert (minVol->Value) : 1.0e-7); //9a
        QuantLib::Volatility _maxVol = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (maxVol) ? (QuantLib::Volatility)ValueHelper::Convert (maxVol->Value) : 4.0); //9a
    	QuantLib::Volatility _rv = (QuantLib::Volatility)(*_ppCapFloor)->impliedVolatility ( _price,  _disc,  _guess,  _accuracy,  _maxEvaluations,  _minVol,  _maxVol );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (_Cdisc != nullptr) _Cdisc->Unlock();
    }
}
Boolean Cephei::QL::Instruments::CCapFloor::IsExpired::get ()
{
    try
    {
    	bool _rv = (bool)(*_ppCapFloor)->isExpired ( );   
        Boolean _nrv = (Boolean)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Cashflows::IFloatingRateCoupon^ Cephei::QL::Instruments::CCapFloor::LastFloatingRateCoupon::get ()
{
    try
    {
    	boost::shared_ptr<QuantLib::FloatingRateCoupon> _rv = (boost::shared_ptr<QuantLib::FloatingRateCoupon>)(*_ppCapFloor)->lastFloatingRateCoupon ( );   
        Cephei::QL::Cashflows::CFloatingRateCoupon^ _nrv = REFNEW Cephei::QL::Cashflows::CFloatingRateCoupon (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
DateTime Cephei::QL::Instruments::CCapFloor::MaturityDate::get ()
{
    try
    {
    	QuantLib::Date _rv = (QuantLib::Date)(*_ppCapFloor)->maturityDate ( );   
        DateTime _nrv = (DateTime)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::ICapFloor^ Cephei::QL::Instruments::CCapFloor::Optionlet (UInt64 n)
{
    try
    {
        QuantLib::Size _n = (QuantLib::Size)ValueHelper::Convert (n); //a
    	boost::shared_ptr<QuantLib::CapFloor> _rv = (boost::shared_ptr<QuantLib::CapFloor>)(*_ppCapFloor)->optionlet ( _n );   
        Cephei::QL::Instruments::CCapFloor^ _nrv = REFNEW Cephei::QL::Instruments::CCapFloor (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
DateTime Cephei::QL::Instruments::CCapFloor::StartDate::get ()
{
    try
    {
    	QuantLib::Date _rv = (QuantLib::Date)(*_ppCapFloor)->startDate ( );   
        DateTime _nrv = (DateTime)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
QL::Instruments::CapFloor::TypeEnum Cephei::QL::Instruments::CCapFloor::Type::get ()
{
    try
    {
    	QuantLib::CapFloor::Type _rv = (QuantLib::CapFloor::Type)(*_ppCapFloor)->type ( );   
        QL::Instruments::CapFloor::TypeEnum _nrv = (QL::Instruments::CapFloor::TypeEnum)_rv;
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Instruments::ICapFloor^ Cephei::QL::Instruments::CCapFloor_Factory::Create (QL::Instruments::CapFloor::TypeEnum type, Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ floatingLeg, Cephei::Core::IVector<Double>^ strikes, Cephei::QL::IPricingEngine^ QL_Pricer)
{
    return REFNEW CCapFloor ( type,  floatingLeg,  strikes,  QL_Pricer);
}
Cephei::QL::Instruments::ICapFloor^ Cephei::QL::Instruments::CCapFloor_Factory::Create (QL::Instruments::CapFloor::TypeEnum type, Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ floatingLeg, Cephei::Core::IVector<Double>^ capRates, Cephei::Core::IVector<Double>^ floorRates, Cephei::QL::IPricingEngine^ QL_Pricer)
{
    return REFNEW CCapFloor ( type,  floatingLeg,  capRates,  floorRates,  QL_Pricer);
}
